package com.swf.seed.netty.server.handler;

import org.jboss.netty.buffer.ChannelBuffer;
import static org.jboss.netty.buffer.ChannelBuffers.*;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;

@ChannelPipelineCoverage("all") 
public class DiscardServerHandler extends SimpleChannelHandler { 
	//消息接收处理
    @Override 
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { 
   /* 	System.out.println(1);
    	 ChannelBuffer  buf = (ChannelBuffer) e.getMessage();  
    	    while(buf.readable()) {  
    	        System.out.println((char) buf.readByte());  
    	    }  */
    	Channel channel = e.getChannel();
    	System.out.println(e.getMessage().toString());
    	channel.write(e.getMessage());
    }  
    
 //异常处理
 @Override 
 public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) { 
     e.getCause().printStackTrace();  
      
     Channel ch = e.getChannel();  
     ch.close();  
 }  
}